/* DISCLAIMER
Original file written by Johnny on Flame.
This piece is protected by the GPLv3 License. Commercial uses of this should only happen with my consent.
JohnnyonFlame (a_t) Hotmail (d_o_t) com
----------------------------------------------------------
This class is the main one.

This front-end has been written by JohnnyonFlame.
Keep in mind that this might agregate work from other people
such as fonts or images, but the source-codes are my own 
intelectual property.
----------------------------------------------------------*/

#include "SDL/SDL.h"

#include "menu.h"
#include "xmlLoader.h"

#include "settings.h"

#include <libxml/tree.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main( int argc, char* args[] ) 
{ 
	//Start SDL 
	SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ); 

	load_SETTINGS("cfg/settings.xml");
	load_XML("cfg/flamefront.xml");

	#ifdef DEBUG
	listReferences();
	#endif

	SDL_ShowCursor(SDL_DISABLE);

	MENU_Init();
	MENU_Unload();

	//Quit SDL, we're going hunting!
	SDL_Quit();

	//Clears the Garbage collector, so that we have no memory leaks
	int i;
	for (i=0;i<=garbage_ammount;i++) {
		#ifdef DEBUG
		printf("Freed %p List.\n", garbage_collector[i]);
		#endif
		free(garbage_collector[i]);
	}

	//Checks if there's a command stacked, if so, launches said command. (deals with launching apps.)
	if (CMD!=NULL) {
		if (PATH!=NULL) if (chdir(PATH)) printf("Error changing DIR: %s\n", strerror(errno)); 
		//if (execl("sh", CMD, NULL) == -1) printf("Error launching file: %s\n", strerror(errno));	
		if (system(CMD) == -1) printf("Error launching file: %s\n", strerror(errno));			
	}
	return 0; 
}


